#ifndef IDATABASEWORKER_H
#define IDATABASEWORKER_H

#include <QObject>
#include <QApplication>
#include <QScopedPointer>
#include <QJsonObject>
#include <QJsonArray>
#include "IDatabase.h"

class IDataBaseWorker : public QObject
{
    Q_OBJECT
public:
    explicit IDataBaseWorker(QObject *parent = nullptr);
    explicit IDataBaseWorker(const SqlLinkParam& par,  QObject *parent = nullptr);
    void setLinkParam(const SqlLinkParam& par);

    QJsonObject getData(QDateTime dt);
    void setData(const QJsonObject &data);
    QString getErrorMsg(){return mIIDb->getErrMsg();}

    QJsonObject getData(QString findText);
    void removeData(QString findText);
protected:
    virtual void refreshStatistics();

public slots:
    void onInit();
    void onQuit();
    void onLinkParamChanged(SqlLinkParam par);
    void onClearData();
    void onDateBeginChanged(QDateTime date);
    void onDateEndChanged(QDateTime date);
    void onDataChanged(QJsonObject data);

signals:
    void sigStatisticsUpdated(QJsonArray data);
    void sigError(QString msg);

protected:
    QScopedPointer<IDatabase> mIIDb;
    QDateTime mDateBegin;
    QDateTime mDateEnd;
};

#endif // IDATABASEWORKER_H
